﻿using MultiLang;
using System;

namespace Rsdn.SmartApp
{
	/// <summary>
	/// Стратегия регистрации active parts.
	/// </summary>
	public class ActivePartRegStrategy : RegElementsStrategy<ActivePartInfo, ActivePartAttribute>
	{
		/// <include file='../CommonXmlDocs.xml' path='common-docs/def-ctor/*'/>
		public ActivePartRegStrategy(IServicePublisher publisher) : base(publisher)
		{}

		/// <summary>
		/// Создать описатель.
		/// </summary>
		public override ActivePartInfo CreateElement(ExtensionAttachmentContext context, ActivePartAttribute attr)
		{
			var contract = typeof (IActivePart);
			if (!contract.IsAssignableFrom(context.Type))
				throw new ExtensibilityException(
					ml.ml_string(7, "Тип '{0}' должен реализовывать интерфейс '{1}'").FormatStr(context.Type, contract));
			return new ActivePartInfo(context.Type);
		}
	}
}